package com.hw.one.collect.zzcity.channel;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * 郑州市HttpClient通道初始化器
 * Created by Administrator on 2016/7/6.
 */
public class ZzCityChannelInitializer extends ChannelInitializer<SocketChannel>{
    private String dataService;
    private int key;
    public ZzCityChannelInitializer(String dataService,int key){
        this.dataService = dataService;
        this.key = key;
    }
    public int getKey(){
        return this.key;
    }
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        //创建入栈处理器并绑定数据
        ZzCityHttpClientInboundHandler handler = new ZzCityHttpClientInboundHandler(dataService,key);

        ch.pipeline()
                .addLast("http-logging",new LoggingHandler(LogLevel.DEBUG))
                .addLast("http-clientCodec",new HttpClientCodec())
                .addLast("http-aggregator",new HttpObjectAggregator(1048576,true))
                .addLast("http-chunkWrite",new ChunkedWriteHandler())
                .addLast(handler);
    }


}
